package org.mozhu.zufang.admin.web.controller;

import org.mozhu.zufang.system.account.entity.User;
import org.mozhu.zufang.system.account.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/dev")
public class DevController {

    @Value("${profile}")
    private String profile;

    @Autowired
    UserService userService;

    @RequestMapping("/profile")
    @ResponseBody
    public String profile() {
        return profile;
    }

    @RequestMapping("test")
    public String test(Model model) {
        model.addAttribute("key", "value-a");
        return "test";
    }

    @RequestMapping("blank")
    public String page(Model model) {
        model.addAttribute("key", "value-a");
        return "blank";
    }

    @RequestMapping("blank1")
    public String page1(Model model) {
        model.addAttribute("key", "value-a");
        return "blank1";
    }

    @RequestMapping("blank2")
    public String page2(Model model) {
        model.addAttribute("key", "value-a");
        return "blank2";
    }

    @RequestMapping("save/user")
    @ResponseBody
    public Object saveUser(@RequestParam("name") String name) {
        User user = new User();
        user.setLoginName(name);
        user.setEmail(name + "@qq.com");
        user.setPlainPassword("123456");
        userService.encryptPassword(user);
        userService.save(user);
        return user;
    }

}
